<?php 
	class DB{
		private $db;
		function __construct()
		{
			$this->db = new mysqli("localhost","root","root","xinleju") or die("数据库连接失败".$this->db->connect_error);
		}

		function createTable($sql)
		{
			$this->db->query($sql);
			if ($this->db->errno) 
			{
				echo "创建表失败".$this->db->error;
				return false;
			}else
			{
				echo "创建表成功";
				return true;
			}
		}

		function insert($sql)
		{
			$this->db->query($sql);
			if($this->db->errno)
			{
				echo  "插入数据失败".$this->db->error;
				return false;
			}
			else
			{
				echo "插入".$this->db->affected_rows."条数据成功";
				echo "<br><br>";
				return true;
			}
		}

		function get($sql)
		{
			$res = $this->db->query($sql);
			if ($this->db->errno) 
			{
				echo "没有获取到数据".$this->db->error;
				return false;
			} else 
			{
				return $res->fetch_all();
			}
		}

		function update($sql)
		{
			$this->db->query($sql);
			if ($this->db->errno) 
			{
				echo "更新数据失败".$this->db->error;
				return false;
			} else 
			{
				echo "成功更新".$this->db->affected_rows."条数据";
				return true;
			}
		}

		function delete($sql)
		{
			$this->db->query($sql);
			if ($this->db->errno) 
			{
				echo "删除数据失败".$this->db->error;
				return false;
			} else 
			{
				echo "成功删除".$this->db->affected_rows."条数据";
				return true;
			}
		}



function getcount($sql)
{
   $res=$this->db->query($sql);
   $count=$this->db->affected_rows;
   return $count;
}
		function __destruct()
		{
			$this->db->close();
		}		
	}	
 ?>